﻿using System;
using System.Collections.Generic;

namespace Hyt.Core.Security
{
    public  class Principal : IPrincipal
    {
        /// <summary>
        /// ID,EF用
        /// </summary>
        public Guid Id
        {
            get
            {
                return _id;
            }
            set { _id = value; }
        }


        public static readonly IPrincipal Anonymous;
        static Principal()
        {
            var p = new Principal();
            p.SetPrincipalType("Anonymous");            
            Anonymous = p;
        }

        private string _principalType;
        private Guid _id;
        protected readonly List<IPrincipal> Parents = new List<IPrincipal>();

        public Principal()
        {
            _principalType = this.GetType().Name;
        }

        public string GetFullId(IPrincipalResolver resolver)
        {
            return resolver.GetPrincipalString(this);
        }

        public Guid GetPrincipalId()
        {
            return _id;
        }

        public string GetPrincipalType()
        {
            return _principalType;
        }

        public virtual List<IPrincipal> GetParents()
        {
            return Parents;
        }

        public void SetPrincipalType(String type)
        {
            _principalType = type;
        }

        public void SetPrincipalId(Guid id)
        {
            _id = id;
        }
    }

    //public sealed class AnonymousPrincipal : Principal
    //{

    //}
}
